/**
 * hydetail管理初始化
 */
var HybrankDetail = {
    id: "HybrankDetailTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
HybrankDetail.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
            {title: '营业部明细', field: 'gYybName', visible: true, align: 'left', valign: 'middle'},
            {title: '股票详情', field: 'gSname', visible: true, align: 'left', valign: 'middle'},
            {title: '总买卖(万)', field: 'gPbuy', visible: true, align: 'left', valign: 'middle'},
            {title: '统计日期', field: 'gTdate', visible: true, align: 'center', valign: 'middle'}
    ];
};

/**
 * 检查是否选中
 */
HybrankDetail.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if(selected.length == 0){
        Feng.info("请先选中表格中的某一记录！");
        return false;
    }else{
        HybrankDetail.seItem = selected[0];
        return true;
    }
};

/**
 * 点击添加hydetail
 */
HybrankDetail.openAddHybrankDetail = function () {
    var index = layer.open({
        type: 2,
        title: '添加hydetail',
        area: ['800px', '420px'], //宽高
        fix: false, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/hybrankDetail/hybrankDetail_add'
    });
    this.layerIndex = index;
};

/**
 * 打开查看hydetail详情
 */
HybrankDetail.openHybrankDetailDetail = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: 'hydetail详情',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/hybrankDetail/hybrankDetail_update/' + HybrankDetail.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 删除hydetail
 */
HybrankDetail.delete = function () {
    if (this.check()) {
        var ajax = new $ax(Feng.ctxPath + "/hybrankDetail/delete", function (data) {
            Feng.success("删除成功!");
            HybrankDetail.table.refresh();
        }, function (data) {
            Feng.error("删除失败!" + data.responseJSON.message + "!");
        });
        ajax.set("hybrankDetailId",this.seItem.id);
        ajax.start();
    }
};

/**
 * 查询hydetail列表
 */
HybrankDetail.search = function () {
    var queryData = {};
    queryData['dm'] = $("#dm").val();
    queryData['date'] = $("#date").val();
    HybrankDetail.table.refresh({query: queryData});
};

$(function () {
    var defaultColunms = HybrankDetail.initColumn();
    var table = new BSTable(HybrankDetail.id, "/hybrankDetail/list", defaultColunms);
    table.setPaginationType("server");
    HybrankDetail.table = table.init();
});
